<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Admin\Attribute;
use Input;
class AttributeController extends Controller
{
    public function index(){
        $data = Attribute::get();
        return view('admin.attribute.index',['data' => $data]);
    }

    public function add(){
        if(Input::method() == 'POST'){
            $data   = Input::all();
            $result = Attribute::insert([
                'attribute_name'   => $data['attribute_name'],
                'attribute_values' => $data['attribute_values'],
            ]);
            return $result ? '1' : '0';
        }else{
            return view('admin.attribute.add');
        }
    }

    public function edit(){
        if(Input::method() == 'POST'){
            $data   = Input::all();
            $result = Attribute::where('id',$data['id']) -> update([
                'attribute_name'   => $data['attribute_name'],
                'attribute_values' => $data['attribute_values'],
            ]);
            return $result ? '1' : '0';
        }else{
            $id       = Input::get('id');
            $data     = Attribute::where('id',$id) -> first();
            return view('admin.attribute.edit',['data' => $data]);
        }
    }

    public function del(){

    }

    public function search(){

    }
}